package com.demo.core.dao.impl;

import java.util.Map;

import com.demo.core.cache.CacheKey;
import com.demo.core.cache.CacheWrapper;
import com.demo.core.dao.ConfigItemDao;
import com.demo.core.dao.impl.base.PageCoreDaoSupport;
import com.demo.core.model.ConfigItem;
import com.demo.core.model.support.GeneralExecuteModel;

/**
 * 配置数据访问层实现类
 * 
 * @author ryuu.kk
 */
public class ConfigItemDaoImpl extends PageCoreDaoSupport<ConfigItem, Long> implements ConfigItemDao {
	/**
	 * 配置空间 
	 */
	protected final static String SQLMAP_NAME_SPACE = "configItemSpace.";
	/**
	 * 数据库的表名
	 */
	protected final static String TABLE_NAME = "T_CORE_CONFIG_ITEM";
	/**
	 * 数据库表的主键名称
	 */
	protected final static String TABLE_PK_NAME = "ID";
	
	@Override
	public int updateStatus(ConfigItem item, Map<String, Object> configStatus) {
		// 清除缓存设置
		CacheWrapper<CacheKey, Object> cache = null;
		if (isUseCache() && (cache = getCache()) != null) {
			cache.clearAll();
		}
		
		configStatus.put("configItem", item);
		return getSqlMapClientTemplate().update(SQLMAP_NAME_SPACE + "changeEnabled", configStatus);
	}

	@Override
	protected String nameSpace() {
		return model.getNameSpace();
	}

	@Override
	protected void doInit(GeneralExecuteModel<Long> model) {
		model.setPk(TABLE_PK_NAME);
		model.setTable(TABLE_NAME);
		model.setNameSpace(SQLMAP_NAME_SPACE);
	}
}